package com.files.convert;

import com.files.model.FileInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
@Service
@Slf4j
public class MultipartFileToFileInfoConverter implements CommonConverter<MultipartFile, FileInfo> {

    @Override
    public  FileInfo convert(MultipartFile multipartFile) {
        FileInfo fileInfo = new FileInfo();
        try {
            fileInfo.setInputStream(multipartFile.getInputStream());
            fileInfo.setBytes(multipartFile.getBytes());
            fileInfo.setOriginalFilename(multipartFile.getOriginalFilename());
            fileInfo.setName(multipartFile.getName());
            fileInfo.setMimeType(multipartFile.getContentType());
            fileInfo.setSize(multipartFile.getSize());
            return fileInfo;
        } catch (IOException e) {
            log.info("MultipartFileToFileInfoConverter exception:{}", e);
        }
        return null;
    }
}
